package com.suwish.pc.util;

import java.util.Arrays;
import java.util.List;

import com.suwish.device.util.Platform;

/**
 * 
 * @author Min
 *
 */
public final class StringUtils {

	
	public static final String REGEX_NEWLINE;
	
	static{
		REGEX_NEWLINE = Platform.getLineSeparator();
	}
	private StringUtils(){}
	
	public static int parseInt(String value){
		if(StringUtils.isEmpty(value)) return -1;
		try{
			return Integer.parseInt(value);
		}catch(Exception e){}
		return -1;
	}
	
	public static String parseCmdPath(String path){
		if(isEmpty(path)) return path;
		return "\"" + path + "\"";
	}
	/**
	 * 
	 * @param value
	 * @return
	 */
	public static boolean isEmpty(String value){
		return value == null ? true : value.trim().isEmpty();
	}
	
	public static boolean isEqual(String value, String target){
		if(isEmpty(value) && isEmpty(target)) return true;
		
		return value == null ? target.equals(value) : value.equals(target);
	}
	public static List<String> convert(String value, String key){
//		int len = value.length();
//		for(int index = 0; index < len ; index ++){
//			System.out.println( value.charAt(index) + " " + (int)value.charAt(index));
//		}
		return Arrays.asList(value.split("[(\r\n)|\n|\r]"));
	}
	
}
